Skip to content

refactor(SqlExpressionFactory): compiled lambda expression cache - #311

Draft
Kevinf63 wants to merge 2 commits into
henkmollema:masterfrom
Kevinf63:master
Draft

refactor(SqlExpressionFactory): compiled lambda expression cache#311
Kevinf63 wants to merge 2 commits into
henkmollema:masterfrom
Kevinf63:master

Conversation

@Kevinf63

@Kevinf63 Kevinf63 commented Jan 1, 2025

Copy link
Copy Markdown

A compiled expression cache factory to create SqlExpression<TEntity>. Creates a compiled lambda expression to instantiate the generic type, passing the parameter and constructor an ISqlBuilder. Delegate for a given type is compiled only once and stored in the ExpressionCache. All subsequent calls use the cached delegate. Nanoseconds is still super quick in fairness, but interesting to see a 83% mean improvement and nearly 49% memory allocation reduction.

BenchmarkDotNet v0.14.0, Windows 11 (10.0.22631.4602/23H2/2023Update/SunValley3)
AMD Ryzen 7 PRO 6850U with Radeon Graphics, 1 CPU, 16 logical and 8 physical cores
.NET SDK 9.0.101
  [Host]     : .NET 9.0.0 (9.0.24.52809), X64 RyuJIT AVX2
  DefaultJob : .NET 9.0.0 (9.0.24.52809), X64 RyuJIT AVX2
Method Mean Error StdDev Ratio RatioSD Gen0 Allocated Alloc Ratio
ActivatorBasedFactory 433.36 ns 5.500 ns 4.876 ns 1.00 0.02 0.0782 656 B 1.00
CompiledExpressionFactory 72.61 ns 1.444 ns 1.877 ns 0.17 0.00 0.0401 336 B 0.51

@sonarqubecloud

sonarqubecloud Bot commented May 7, 2026

Copy link
Copy Markdown

@Kevinf63
Kevinf63 marked this pull request as ready for review May 7, 2026 11:57
@Kevinf63
Kevinf63 marked this pull request as draft May 7, 2026 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant